# attn-to-prec

Replication data and code for "Agenda Setting and Attention to Precedent in the U.S. Federal Courts".
This archive contains subdirectories for the replication data ("data"), replication code ("code"), and an R package providing functions used in the replication code ("bapvar").
To replicate the full results from the paper unfortunately requires months of computing time.
So we have, in addition to the replication data, provided summary data on the results from the models used for the paper, so that you may replicate results from a random subset of the precedents and compare to our precedent-level reported results here.
So, there is code to replicate a random subset of the results (and if you have the computing time, a simple change of course allows you to replicate the full results), as well as code to reproduce all tables and figures in the paper from the precedent-level results included in the archive.

## Replication and Reproduction

To replicate a random subset of the models and reproduce the paper's tables and figures:
  - Ensure system dependencies are satisfied, specifically that you have `jags` and `R` installed, as well as tools to install R packages from source and compile C++ code.
  - Ensure that you have the following R extension packages installed from CRAN:
    + dplyr
    + tidyr
    + rjags
    + runjags
    + BayesPostEst
    + Rcpp
    + RcppArmadillo
    + bggum
    + (and dependencies of above packages such as "coda")
  - Install the included R extension package "bapvar", such as through the R command `devtools::install("bapvar")`.
  - Run the R scripts in the "code" subdirectory in the following order:
    + "01-sampling.R"
    + "02-frequency-of-effects.R"
    + "03-examples.R"
    + "04-magnitude-of-effects.R"

## Contents

### bapvar/

The "bapvar" folder contains an R package, "bapvar", that provides functions for running the BaP-VAR model (Brandt and Sandler 2012) and generating impulse responses and forecast error variance decomposition, tailored *specifically* to the model in the paper (though it could probably be generalized with minimal work).
The package contains documentation of each of the functions provided.

### code/

The "code" folder contains five files:
  - "00-util.R", which contains various convenience wrappers and helper functions used in the remaining scripts. The functions are documented roxygen-style there.
  - "01-sampling.R", which is an R script that allows you to generate posterior samples for the models specified in the paper for some subset of the precedents.
  - "02-frequency-of-effects.R", which is an R script that ensures the reported results replicate for the samples generated in "01-sampling.R" and reproduces Tables 1 and 2 and Figure 1.
  - "03-examples.R", which is an R script that replicates the results for the example cases presented in the paper, *Smith* and *Watts*, replicating Tables 3 and 4 and Figures 2 and 3.
  - "04-magnitude-of-effects.R", which is an R script that reproduces Figures 4, 5, 6, and 7.

### data/

The "data" folder contains five files:
  - "citation-data.csv", which contains precedent-year-level data on citations to U.S. Supreme Court precedents decided between 1946 and 1985
  - "coef-signs.csv", which contains the "sign" for lag coefficients in all optimal-lag models run for the paper, i.e., whether the lag coefficient's 95% credible interval bounded zero, and if not, indicating which side of zero the credible interval lied.
  - "coef-summaries.csv", which contains summary data on the posterior draws for lag coefficients in all one-lag models run for the paper
  - "dynamic-summaries.csv", which contains summary data on impulse responses and forecast error variance decomposition calculated from the posterior draws for all one-lag models run for the paper
  - "codebook.pdf", which contains information on how the data for the paper were gathered, and documenting the contents of "citation-data.csv", "coef-summaries.csv", and "dynamic-summaries.csv"

## References

Brandt, Patrick T. and Todd Sandler. 2012. "A Bayesian Poisson Vector Autoregression Model."" *Political Analysis*, 20(3): 292-315.

